/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
 * Description:
 * Author: g00421808
 * Create: 6/24/2022
 * Notes:
 */

#ifndef JSBIND_VALUE_H
#define JSBIND_VALUE_H

#include <string>

namespace Jsb {
class Value {
public:
    virtual ~Value() = default;

    operator bool() { return GetBool(); }

    operator int() { return GetInt(); }

    operator int64_t() { return GetInt64(); }

    operator double() { return GetDouble(); }

    operator float() { return GetFloat(); }

    operator std::string() { return GetString(); }

    template<typename T>
    operator T&() {
        return *(reinterpret_cast<T*>(GetDataReference()));
    }

    template<typename T>
    operator T*() {
        return *(reinterpret_cast<T**>(GetDataReference()));
    }

    virtual operator Value*() = 0;

    virtual bool GetBool() const { return std::numeric_limits<bool>::quiet_NaN(); }

    virtual int32_t GetInt() const { return std::numeric_limits<int32_t>::quiet_NaN(); }

    virtual int64_t GetInt64() const { return std::numeric_limits<int64_t>::quiet_NaN(); }

    virtual double GetDouble() const { return std::numeric_limits<double>::quiet_NaN(); };

    virtual float GetFloat() const { return std::numeric_limits<float>::quiet_NaN(); };

    virtual std::string GetString() const { return std::string(); }

    virtual char* GetCString() { return nullptr; }

protected:
    virtual void* GetDataReference() = 0;
};
} // namespace Jsb
#endif //JSBIND_VALUE_H
